package com.hut.oa.model.dao.system;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.Menu;


public interface MenuDao extends CrudRepository<Menu, Long>{
	List<Menu> findAll();
	
	List<Menu> findByParentIsNullOrderBySeq();//查询所有父菜单
	
	List<Menu> findByParentOrderBySeq(Menu parents);//查询所有父菜单对应的子菜单
	
	List<Menu> findByOpenAndTypeOrderBySeq(boolean open,String type);//查询所有能用的菜单
	
	List<Menu> findByTypeOrderBySeq(String type);//查询所有菜单
	
	Menu findById(Long id);
	
	int countByParent(Menu parents);
	
	@Query("update Menu m set m.seq=:seq where m.id=:id")
	@Modifying
	int updateSeq(@Param("seq")Integer seq,@Param("id")Long id);//修改排序
	
	@Query("update Menu m set m.open=:open where m.id=:id")
	@Modifying
	int updateOpen(@Param("open")boolean open,@Param("id")Long id);//修改状态

}
